#ifndef ELBUTTON_H
#define ELBUTTON_H

#include <QUrl>
#include "elabstractbutton.h"
#include "eltheme.h"

class ElButton : public ElAbstractButton
{
    Q_OBJECT
public:
    enum Type { Default, Plain, Rounded };

    ElButton(QWidget *parent = nullptr);
    ElButton(const QString &text, QWidget *parent = nullptr);

    void setTheme(ElTheme::Type type);
    ElTheme theme() const;

    Type type() const;
    void setType(Type type);

    static const int Icon_Size;
    static const int Padding_Lr;
    static const int Padding_Tb;
    static const int Spacing;

protected:
    bool event(QEvent *e) override;
    void paintEvent(QPaintEvent *e) override;
    void enterEvent(QEnterEvent *e) override;
    void leaveEvent(QEvent *e) override;
    void mousePressEvent(QMouseEvent *e) override;
    void mouseReleaseEvent(QMouseEvent *e) override;
    void initPalette() override;

    ElTheme _theme;
    Type _type = Default;
};

class ElCircleButton : public ElButton
{
    Q_OBJECT
public:
    ElCircleButton(QWidget *parent = nullptr);
    ElCircleButton(ElIcon *icon, QWidget *parent = nullptr);

    void setIcon(ElIcon *icon);
    void setIcon(const QString &filename, int iconSize = 16);

    qreal radius() const;
    void setRadius(qreal radius);

signals:
    void radiusChanged(qreal radius);

protected:
    void paintEvent(QPaintEvent *e) override;

    qreal _radius = 20;

private:
    // circle button is not allowed to set text or type.
    using ElButton::setText;
    using ElButton::setType;
    using ElButton::text;
    using ElButton::type;
    Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged FINAL)
};

class ElTextButton : public ElButton
{
    Q_OBJECT
public:
    using ElButton::ElButton;

    bool isClipped() const;
    void setClipped(bool clipped);

protected:
    void paintEvent(QPaintEvent *e) override;
    void initPalette() override;

private:
    using ElButton::setType;
    using ElButton::type;

    bool _clipped = false;
};

class ElLink : public ElTextButton
{
    Q_OBJECT
public:
    using ElTextButton::ElTextButton;

    QUrl target() const;
    void setTarget(const QUrl &target);

    bool hasUnderline() const;
    void setUnderline(bool b);

signals:
    void targetChanged(const QUrl &target);

protected:
    void initPainter(QPainter *painter) const override;
    void mouseReleaseEvent(QMouseEvent *e) override;

    QUrl _target;
    bool _hasUnderline = true;

private:
    using ElTextButton::pressed;
    using ElTextButton::released;
    using ElTextButton::textChanged;
    Q_PROPERTY(QUrl target READ target WRITE setTarget NOTIFY targetChanged FINAL)
};

#endif // ELBUTTON_H
